import { ref, reactive } from 'vue'
import { ChatCreateSessionConfig } from '~/api/manager'
import { showModel, toast } from '~/composables/util'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { type } from 'windicss/utils'



export function sessionAddConfig() {
    const router = useRouter()
    const formDrawerRef = ref(null)
    const formRef = ref(null)
    const loading = ref(false)
    const form = reactive({
      session_id: '', // 会话ID
      knowledge_ids: [],
      network: null
    })
  
    const rules = {
      network: [
        {type:"boolean"}
      ]
    }
  
    const onSubmit = () => {
      formRef.value.validate((valid) => {
        if (!valid) {
          return false
        }
        loading.value = true
        console.log('chatManger', form)
        ChatCreateSessionConfig(form)
          .then((res) => {
            if (res.code === 0) {
              toast('成功')
              formDrawerRef.value.close()
  
            } else {
              toast(res.message, 'error')
            }
          })
          .finally(() => {
            loading.value = false
          })
      })
    }
  
    const openRegisterForm = () => formDrawerRef.value.open()
  
    return {
      formDrawerRef,
      formRef,
      form,
      onSubmit,
      rules,
      openRegisterForm,
      loading
    }
  }



